from sqlalchemy.orm import sessionmaker, scoped_session
from orm01 import engine, Student, Employee
session_factory = sessionmaker(bind=engine)
Session = scoped_session(session_factory)
# 内连接
result01 = Session.query(Student.name, Employee.desc).join(Employee, Employee.sid == Student.id)
# 左连接  query后面紧跟第一个属性的表,默认是主表
result = Session.query(Student.name, Employee.desc).outerjoin(Employee, Employee.sid == Student.id)
# 组合
result__all = result01.union(result).all()
result__all = result01.union_all(result).all()
# 一对多情况下,会返回两条数据
result01 = Session.query(Student.name, Employee.desc)\
    .join(Employee, Employee.sid == Student.id).filter(Student.name == "哈哈哈").all()
for row in result01:
    print(row)